﻿/*************************************************************************
 *  Copyright © 2023-2030 Administrator. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：CustomBuildProcess
 *  文件：PackageInitializer.cs
 *  作者：Administrator
 *  日期：2024/11/20 22:10:41
 *  功能：Nothing
*************************************************************************/

using System.IO;
using UnityEditor;
using UnityEngine;

namespace CustomBuildProcess.Editor
{
    [InitializeOnLoad]
    public class PackageInitializer
    {
        static PackageInitializer()
        {
            EditorApplication.delayCall += OnEditorLoad;
        }

        private static void OnEditorLoad()
        {
            CreateBuildInfoResources();
        }

        private static void CreateBuildInfoResources()
        {
            try
            {
                if (!Directory.Exists(PathManager.BuildDataPath))
                {
                    Directory.CreateDirectory(PathManager.BuildDataPath);
                }

                if (!File.Exists(PathManager.BuildConfigPath))
                {
                    BuildInfoConfig.CreateBuildInfoAsset(PathManager.BuildConfigPath);
                    Debug.Log($"No BuildSettingConfig.asset file found. Creating default at {PathManager.BuildConfigPath}");
                }

                AssetDatabase.Refresh();
            }
            catch (System.Exception ex)
            {
                Debug.LogError($"Creating BuildSettingConfig.asset failed: {ex.Message}");
            }
        }
    }
}

